package com.xueyi.aixihu.controller;

import com.xueyi.aixihu.controller.base.BaseController;
import com.xueyi.aixihu.entity.vo.DtAreaOrVillageVo;
import com.xueyi.aixihu.entity.vo.DtFindByAreaVo;
import com.xueyi.aixihu.reqeust.DtAddVillageReq;
import com.xueyi.aixihu.reqeust.DtFindByAreaAndVillageReq;
import com.xueyi.aixihu.response.DtFindByAreaResponse;
import com.xueyi.aixihu.response.base.BaseResponse;
import com.xueyi.aixihu.service.DtAreaManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author yuyu
 * @date : 2022/8/17
 * @Description : 村/社区管理接口类
 */
@RestController
public class DtAreaManageController extends BaseController {
    //注入service层
    @Autowired
    private DtAreaManageService dtAreaManageService;

    /**
     * 获取村/社区的集合
     * @param dtFindByAreaAndVillageReq
     * @return
     */
    @PostMapping("/findBy/areaAndVillage")
    public DtFindByAreaResponse findByAreaAndVillage(DtFindByAreaAndVillageReq dtFindByAreaAndVillageReq) {
        DtFindByAreaResponse response = dtAreaManageService.findByAreaAndVillage(dtFindByAreaAndVillageReq);
        return  response;
    }

    /**
     *  添加村/社区
     * @param dtAddVillageReq
     * @return
     */
    @PostMapping("/add/areaOrVillage")
    public BaseResponse addVillage(DtAddVillageReq dtAddVillageReq) {
        BaseResponse baseResponse = dtAreaManageService.addVillage(dtAddVillageReq);
        return baseResponse;
    }

    /**
     *  查询单条数据
     * @param id
     * @return
     */
    @PostMapping("/findBy/oneArea")
    public BaseResponse<DtFindByAreaVo> findByOneArea(Integer id) {
        BaseResponse<DtFindByAreaVo> response = dtAreaManageService.findByOneArea(id);
        return response;
    }

    /**
     * 改变状态
     * @param id
     * @param isValid
     * @return
     */
    @PostMapping("/update/isValid")
    public BaseResponse updateIsValid(Integer id,Integer isValid){
        BaseResponse baseResponse = dtAreaManageService.updateIsValid(id, isValid);
        return baseResponse;
    }

    /**
     *  修改村镇信息
     * @param dtFindByAreaVo
     * @return
     */
    @PostMapping("/update/villageInformation")
    public BaseResponse updateVillageInformation(@Valid DtFindByAreaVo dtFindByAreaVo) {
        BaseResponse baseResponse = dtAreaManageService.updateVillageInformation(dtFindByAreaVo);
        return baseResponse;
    }

    /**
     *  查询村和社区的个数
     * @return
     */
    @PostMapping("/findBy/areaTotal")
    public BaseResponse<DtAreaOrVillageVo> findByAreaOrVillageCount() {
        BaseResponse<DtAreaOrVillageVo> response = dtAreaManageService.findByAreaOrVillageCount();
        return response;
    }


}
